
from whiff.middleware import misc
from whiff import whiffenv
from whiff import resolver
import os

def viewSource(env, start_response):
    ep = env["whiff.entry_point"]
    [dir, fn] = os.path.split(ep)
    if fn=="colorize":
        env = resolver.process_cgi(env, parse_cgi=True)
        fn = whiffenv.cgiGet(env, "page")
    filename = fn+".whiff"
    filename = filename.replace(".", ".<br>\n")
    start_response("200 OK", [('Content-Type', "text/html")])
    yield '<a href="colorize?page='
    yield fn
    yield '"> view source<br> '
    yield filename
    yield '</a>'

__wsgi__ = viewSource

def test():
    L = viewSource({"whiff.entry_point": "aaa/bbb.ccc.ddd"}, misc.ignore)
    print "test result", "".join(list(L))

if __name__=="__main__":
    test()

